//
//  UtilsMacros.h
//
//

#ifndef UtilsMacros_h
#define UtilsMacros_h


//=============== 网络相关 ==================
#define BaseUrl @"https://admin.boxingkeji.com/api/"
#define SHAREURL @"https://apps.apple.com/us/app/id6502909242"
#define APPCOMENTURL @"itms-apps://itunes.apple.com/app/id6502909242?action=write-review"
#define QZUserInfoKey @"QZUserInfoKey" //存储用户数据
#define LOGIN_KEY @"loginuserlogin"
#define LOGIN_OUT @"loginuserout"
#define VIDOE_DRAFT_KEY @"VIDOE_DRAFT_KEY"
#define HOME_VIDOE_UPLOAD_KEY @"HOME_VIDOE_UPLOAD_KEY"
#define HOME_TIP_GUIDE_KEY @"HOME_TIP_GUIDE_KEY"

#define DAY         @"drak"
#define NIGHT       @"night"


#define KISIPAD [[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPad
//=============== 机型相关 ==================
#define kStatusBarHeight \
({\
    CGFloat height = 0.0;\
    if (@available(iOS 13.0, *)) {\
        CGFloat topHeight = [UIApplication sharedApplication].windows.firstObject.safeAreaInsets.top;\
        height = topHeight ? topHeight : 20.0;\
    }else {\
        height = [[UIApplication sharedApplication] statusBarFrame].size.height;\
    }\
    (height);\
})\

//底部安全高度
#define KSafeAreaBottomHeight \
({\
    CGFloat height = 0.0;\
    if (@available(iOS 13.0, *)) {\
        NSSet *set = [UIApplication sharedApplication].connectedScenes;\
        UIWindowScene *windowScene = [set anyObject];\
        UIWindow *window = windowScene.windows.firstObject;\
        height = window.safeAreaInsets.bottom;\
    } else if (@available(iOS 11.0, *)) {\
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;\
        height = window.safeAreaInsets.bottom;\
    }\
    (height);\
})\

#define  KScreen_W             ([UIScreen mainScreen].bounds.size.width)
#define  KScreen_H             ([UIScreen mainScreen].bounds.size.height)
#define ScreenFrame [UIScreen mainScreen].bounds
//状态栏高度
#define  KBaseNavi_Height      44
#define  KNav_H                (kStatusBarHeight+KBaseNavi_Height)
#define  KTab_H                (49+KSafeAreaBottomHeight)
#define  KDif_H                (kStatusBarHeight - 24)
#define  GETPIXEL              (KScreen_W / 375) //按375屏宽设置 获取像素比
#define  K_AUTOLAYOUT_W(with) (with * GETPIXEL)

#define  GETPIXEL1              (KScreen_W / 667) //按375屏宽设置 获取像素比
#define  K_AUTOLAYOUT_W1(with) (with * GETPIXEL1)
//=============== image ==================
#define KImageNamed(name)    [UIImage imageNamed:(name)]
#define KImageUrl(url)       [url hasPrefix:@"http"] ? [NSURL URLWithString:url]:[NSURL URLWithString:url relativeToURL:[NSURL URLWithString:QiNiuBaseUrl]]
#define KImageUrlString(url) [url hasPrefix:@"http"] ? url:[NSString stringWithFormat:@"%@%@",QiNiuBaseUrl,url]
#define KUrlString(url) [NSURL URLWithString:(url)]

#define KMutableDic(sendDic) NSMutableDictionary *sendDic = [NSMutableDictionary new];
//=============== 便捷方法 ==================
#define KWeak(name,weakName)  __weak typeof(name) weakName = name;
#define KWeakSelf   __weak typeof(self) weakSelf = self;
#define KStrongSelf   __strong typeof(self) strongSelf = self;//只能修饰weakSelf 用来为了防止弱引用内存提前释放

#define ShowHud(String)  [MBProgressHUD showMessageAutoHide:String];
#define ShowMBLoading [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
#define HideMBLoading [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].delegate.window animated:YES];


//NSUserDefaults取值 同步存值
#define USERDEFAULT_GetValue(key) [[NSUserDefaults standardUserDefaults] valueForKey:key]
#define USERDEFAULT_SetValue(_value_,_key_) [[NSUserDefaults standardUserDefaults] setValue:_value_ forKey:_key_];\
[[NSUserDefaults standardUserDefaults] synchronize]


// UILabel 初始化
#define UILABEL_ALLOC(X,Y,x,y) [[UILabel alloc] initWithFrame:CGRectMake(X,Y,x,y)]
// UITextField 初始化
#define UITEXTFIELD_ALLOC(X,Y,x,y) [[UITextField alloc] initWithFrame:CGRectMake(X,Y,x,y)]
// UIView 初始化
#define UIVIEW_ALLOC(X,Y,x,y) [[UIView alloc] initWithFrame:CGRectMake(X,Y,x,y)]
// UIImageView 初始化
#define UIIMAGEVIEW_ALLOC(X,Y,x,y) [[UIImageView alloc] initWithFrame:CGRectMake(X,Y,x,y)]

//=============== log =================
//#ifdef DEBUG
//#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d  \t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
//#else
//#define NSLog(FORMAT, ...) nil
//#endif

#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#define debugMethod() NSLog(@"%s", __func__)
#else
#define NSLog(...)
#define debugMethod()
#endif

// 适配比例，一般为1：1.25...
#define ZoomValue 1.25f
// 字符串是否为空
#define IsStrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqualToString:@"(null)"]) || ([(_ref) isEqualToString:@"(Null)"]) || ([(_ref) isEqualToString:@"(NULL)"]) || ([(_ref) isEqualToString:@"(null)"]) || ([(_ref) isEqualToString:@"<null>"]) || ([(_ref) isEqual:[NSNull null]]) || ([(_ref) isEqualToString:@""]) || ([(_ref) length] == 0))

// 数组是否为空
#define IsArrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) || ([(_ref) count] == 0))
/**
 *  设备判断...
 */
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

#define is_Pad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

#define LEmpty(_ref) [NSString filterStringEmpty:_ref]

#define FORMAT(f, ...)      [NSString stringWithFormat:f, ## __VA_ARGS__]
#endif /* UtilsMacros_h */
